﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Globalization.NumberFormatting;
using Windows.UI.Xaml.Data;

namespace Enough.Converter
{
    public class NumberToTextConverter : IValueConverter
    {
        private static DecimalFormatter _formatter = new DecimalFormatter { IsGrouped = true, FractionDigits = 0 };

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is double)
            {
                double doubleValue = (double)value;
                int digits = (parameter != null) ? int.Parse(parameter.ToString()) : CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
                string result = string.Format("{0:N" + digits + "}", doubleValue);
                return result;
            }
            return string.Format("{0:N0}", value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
